﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="admin_node_task.aspx.cs" Inherits="TRPOP.CMS.Web.Admin.admin_node_task" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../../js/jquery.js" type="text/javascript"></script>
    <script src="../../js/utils.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        var nodeinfo, pageSize = 0, totalPage = 10, currtentPage = 1, ids = '', _index = 1;

        $(document).ready(function () {

            nodeinfo = top.arrNodeTask[UrlParm.parm('_node_task_id')];
            //alert(nodeinfo.ac);
            if (nodeinfo.ac == 'refresh') {//结点更新操作
                pageSize = nodeinfo.onceOper;
                if (nodeinfo.refresh_content == "1") {
                    get_refersh_contentids(); //更新内容
                }
                else if (nodeinfo.refresh_extra == "1") {
                    get_refersh_extraids(); //更新附加发布
                }
                else if (nodeinfo.refresh_index == "1") { //更新首页
                    refersh_index();
                }
            }
            else if (nodeinfo.ac == 'nodepub') { //结点发布操作
                pageSize = nodeinfo.onceOper;
                get_nodepub_contentids(); //发布内容
            }
        });
        //分页获取更新的ids
        var index_num =0;
        function get_refersh_contentids() {

            if (currtentPage <= totalPage) {
                index_num = (currtentPage - 1) * pageSize + 1;
                top.TaskInfoShow("开始更新内容(" + index_num + "," + (currtentPage * pageSize) + ")（" + nodeinfo.name + "）……", Math.random());
                $.ajax({
                    type: "POST",
                    url: "admin_taskanalysis.aspx?ac=ajax_contentrefresh&nodeid=" + nodeinfo.nodeid + "&pageSize=" + nodeinfo.onceOper + "&currtentPage=" + currtentPage + "&t=" + Math.random(),
                    async: true,
                    error: function () { top.TaskInfoShow('获取内容信息id(' + ((currtentPage - 1) * pageSize + 1) + ',' + (currtentPage * pageSize) + ')（' + nodeinfo.name + '）出错', Math.random()); currtentPage++; get_refersh_contentids(); },
                    success: function (msg) {
                        var result = eval("result=" + msg);
                        totalPage = result.totalPage;
                        ids = result.ids;
                        refersh_content();
                    }
                });
            }
            else {
                top.TaskInfoShow("结点[" + nodeinfo.name + "]内容更新完成", Math.random());
                get_refersh_extraids();
            }
        }
        //更新内容页
        function refersh_content() {
            index_num = (currtentPage - 1) * pageSize + 1;
            $.ajax({
                type: "POST",
                url: "admin_taskexec.aspx",
                data: 'ac=content&contentid=' + ids + '&t=' + Math.random(),
                async: true,
                error: function () {
                    top.TaskInfoShow("更新内容页(" + index_num + "," + (currtentPage * pageSize) + ")（" + nodeinfo.name + "）失败", Math.random());
                     currtentPage++;
                    get_refersh_contentids();
                },
                success: function (msg) {

                    msg = eval("msg=" + msg);
                    if (msg.result == "1") {
                    }
                    else {
                    }
                    top.TaskInfoShow("更新内容(" + index_num + "," + (currtentPage * pageSize) + ")（" + nodeinfo.name + "）成功", Math.random());
                    currtentPage++;
                    get_refersh_contentids();
                }
            });
        }
        //获取附加发布信息Id
        function get_refersh_extraids() {
            if (nodeinfo.refresh_extra == "1") {
                $.ajax({
                    type: "POST",
                    url: "admin_taskanalysis.aspx?ac=ajax_extrarefresh&nodeid=" + nodeinfo.nodeid + "&t=" + Math.random(),
                    async: true,
                    error: function () { ids = ""; top.TaskInfoShow('获取附加发布信息id（' + nodeinfo.name + '）出错', Math.random()); },
                    success: function (msg) {
                        var result = eval("result=" + msg);
                        ids = result.ids;
                        refersh_extra();
                    }
                });
            }
            else {
                refersh_index();
            }
        }
        //更新附加发布信息
        function refersh_extra() {
            top.TaskInfoShow("开始更新附加发布页（" + nodeinfo.name + "）……", Math.random());
            $.ajax({
                type: "POST",
                url: "admin_taskexec.aspx",
                data: 'ac=Extra&index=1&Extras=' + ids + '&countNum=1&nodeid=' + nodeinfo.nodeid + '&t=' + Math.random(),
                async: true,
                error: function () {
                    top.TaskInfoShow("更新附加发布页（" + nodeinfo.name + "）失败", Math.random());

                },
                success: function (msg) {

                    msg = eval("msg=" + msg);
                    if (msg.result == "1") {
                    }
                    else {
                    }
                    top.TaskInfoShow("更新附加发布页（" + nodeinfo.name + "）成功", Math.random());
                    refersh_index();
                }
            });
        }

        //发页获取要发布的信息ids
        function get_nodepub_contentids() {
            if (currtentPage <= totalPage) {
                index_num = (currtentPage - 1) * pageSize + 1;
                top.TaskInfoShow("开始发布内容(" + index_num + "," + (currtentPage * pageSize) + ")（" + nodeinfo.name + "）……", Math.random());
                $.ajax({
                    type: "POST",
                    url: "admin_taskanalysis.aspx?ac=ajax_contentpub&nodeid=" + nodeinfo.nodeid + "&pageSize=" + nodeinfo.onceOper + "&currtentPage=" + currtentPage + "&t=" + Math.random(),
                    async: true,
                    error: function () { top.TaskInfoShow('获取内容信息id(' + ((currtentPage - 1) * pageSize + 1) + ',' + (currtentPage * pageSize) + ')（' + nodeinfo.name + '）出错', Math.random()); currtentPage++; get_nodepub_contentids(); },
                    success: function (msg) {
                        var result = eval("result=" + msg);
                        totalPage = result.totalPage;
                        ids = result.ids;
                        nodepub_content();
                    }
                });
            }
            else {
                top.TaskInfoShow("结点[" + nodeinfo.name + "]内容发布完成", Math.random());
                refersh_index();
            }
        }
        //发布内容
        function nodepub_content() {
            index_num = (currtentPage - 1) * pageSize + 1;
            $.ajax({
                type: "POST",
                url: "admin_taskexec.aspx",
                data: 'ac=content&contentid=' + ids + '&t=' + Math.random(),
                async: true,
                error: function () {
                    top.TaskInfoShow("发布内容页(" + index_num + "," + (currtentPage * pageSize) + ")（" + nodeinfo.name + "）失败", Math.random());
                    currtentPage++;
                    get_nodepub_contentids();
                },
                success: function (msg) {

                    msg = eval("msg=" + msg);
                    if (msg.result == "1") {
                    }
                    else {
                    }
                    top.TaskInfoShow("发布内容(" + index_num + "," + (currtentPage * pageSize) + ")（" + nodeinfo.name + "）成功", Math.random());
                    currtentPage++;
                    get_nodepub_contentids();
                }
            });
        }





        //刷新首页
        function refersh_index() {
            if (nodeinfo.refresh_index == "1" && _index <= parseInt(nodeinfo.htmlpagecount)) {
               if(_index==1)
               top.TaskInfoShow("开始更新首页（" + nodeinfo.name + "）……", Math.random());
                $.ajax({
                    type: "POST",
                    url: "admin_taskexec.aspx",
                    data: 'ac=node&index=' + _index + '&countNum=1&nodeid=' + nodeinfo.nodeid + '&t=' + Math.random(),
                    async: true,
                    error: function () {
                        top.TaskInfoShow("更新首页 页次" + _index + "（" + nodeinfo.name + "）失败", Math.random());
                        _index++;                      
                        refersh_index();
                    },
                    success: function (msg) {
                        msg = eval("msg=" + msg);
                        if (msg.result == "1") {
                            top.TaskInfoShow("更新首页 页次" + _index + "（" + nodeinfo.name + "）成功", Math.random());
                            _index++;
                            refersh_index();
                        }
                        else {
                            _index++;
                            refersh_index();
                        }
                       

                    }
                });
            }
            else {//调用上级窗口信息
                if (nodeinfo.refresh_index == "1")
                { top.TaskInfoShow("首页更新完成（" + nodeinfo.name + "）", Math.random()); }
                nodeinfo.exec = 1;
                //开始下一结点任务
                top._node_task_id++;                
                top.node_task_run();              
            }
        }
        
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <iframe id="run_task" name="run_task" />
    </div>
    </form>
</body>
</html>
